package ch.headshot.photomap.client;

import ch.headshot.photomap.client.album.AlbumPopup;

import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.event.MarkerClickHandler;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.geom.Point;
import com.google.gwt.maps.client.geom.Size;
import com.google.gwt.maps.client.overlay.Icon;
import com.google.gwt.maps.client.overlay.Marker;
import com.google.gwt.maps.client.overlay.MarkerOptions;

public class Photomarker extends Marker implements MarkerClickHandler {

	private final String url;
	private final MapWidget map;

	public Photomarker(LatLng latLng, String url, MapWidget map) {
		super(latLng, getOptions(url));
		this.url = url;
		this.map = map;
		addMarkerClickHandler(this);
	}

	private static MarkerOptions getOptions(String url) {
		MarkerOptions options = MarkerOptions.newInstance();
		Icon icon = Icon.newInstance(url);
		icon.setDragCrossAnchor(Point.newInstance(0, 0));
		icon.setIconAnchor(Point.newInstance(0, 0));
		icon.setInfoWindowAnchor(Point.newInstance(0, 0));
		icon.setIconSize(Size.newInstance(40, 40));
		options.setClickable(true);
		options.setDraggable(false);
		options.setTitle("test");
		options.setIcon(icon);
		options.setAutoPan(true);
		options.setDragCrossMove(true);
		options.setBounceGravity(1.0);
		return options;
	}

	public void onClick(MarkerClickEvent event) {
		String albUrl = url.replace("images/atsa", "ats");
		albUrl = albUrl.replace("jpg", "htm");
		AlbumPopup.open(albUrl);
		// ScrollPanel panel = new ScrollPanel();
		// Image image = new Image(url);
		// panel.add(image);
		// InfoWindowContent content = new InfoWindowContent(panel);
		// content.setMaxContent(image);
		// content.setMaxTitle("test");
		//
		// map.getInfoWindow().open(this, content);
	}
}
